home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / ZTIMER11.ARJ / MODEL.MAC < prev    next >
Text File  |  1992-04-20  |  5KB  |  216 lines

  1. ;****************************************************************************
  2. ;*
  3. ;*                    Copyright (C) 1991 Kendall Bennett.
  4. ;*                            All rights reserved.
  5. ;*
  6. ;* Filename:    $RCSfile: model.mac $
  7. ;* Version:        $Revision: 1.2 $
  8. ;*
  9. ;* Language:    Turbo Assembler 2.5
  10. ;* Environment:    IBM PC (MS DOS)
  11. ;*
  12. ;* Description:    Macros to provide memory model independant assembly language
  13. ;*                module for Borland C++.
  14. ;*
  15. ;* NOTES:    When you declare the data and code segments, you should specify
  16. ;*            a name to be used. This name should be the name of the file
  17. ;*             being assembled, but you may use the same name for mutiple
  18. ;*            modules if you wish so that the data and code for these modules
  19. ;*            are all contained in the same segments. Of course the maximum
  20. ;*            size of data and code must be less than 64k respectively.
  21. ;*
  22. ;* $Id: model.mac 1.2 91/11/12 11:36:14 kjb Exp $
  23. ;*
  24. ;* Revision History:
  25. ;* -----------------
  26. ;*
  27. ;* $Log:    model.mac $
  28. ;* Revision 1.2  91/11/12  11:36:14  kjb
  29. ;* Added macro for static model independant procedures.
  30. ;* 
  31. ;* Revision 1.1  91/09/20  16:26:07  kjb
  32. ;* Initial revision
  33. ;* 
  34. ;****************************************************************************
  35.  
  36. ; Define symbols codesize and datasize depending on the requested memory
  37. ; model.
  38.  
  39. ifdef    __TINY__
  40.         codesize    EQU    0
  41.         datasize    EQU    0
  42.         hugedata    EQU    0
  43. else
  44. ifdef     __MEDIUM__
  45.         codesize    EQU    1
  46.         datasize     EQU    0
  47.         hugedata    EQU    0
  48. else
  49. ifdef     __COMPACT__
  50.         codesize    EQU    0
  51.         datasize    EQU    1
  52.         hugedata    EQU    0
  53. else
  54. ifdef    __LARGE__
  55.         codesize    EQU    1
  56.         datasize    EQU    1
  57.         hugedata    EQU    0
  58. else
  59. ifdef    __HUGE__
  60.         codesize    EQU    1
  61.         datasize    EQU 1
  62.         hugedata    EQU    1
  63. else
  64.         codesize    EQU    0        ; Default to small model if none specified
  65.         datasize     EQU    0
  66.         hugedata    EQU    0
  67. endif
  68. endif
  69. endif
  70. endif
  71. endif
  72.  
  73. ; Macros for obtaining size of pointer for model requested.
  74.  
  75. if datasize
  76.         DPTR        EQU    DWORD
  77.         dptrsize    EQU    4        ; Size of a data pointer
  78. else
  79.         DPTR        EQU    WORD
  80.         dptrsize    EQU    2
  81. endif
  82.  
  83. if codesize
  84.         CPTR        EQU    DWORD
  85.         FPTR        EQU    FAR
  86.         cptrsize    EQU    4        ; Size of a code pointer
  87. else
  88.         CPTR        EQU    WORD
  89.         FPTR        EQU    NEAR
  90.         cptrsize    EQU    2
  91. endif
  92.  
  93. ; Macros for procedure definitions given a name. Note that they also exports
  94. ; the symbol with the PUBLIC directive, so that it need not be explicitly
  95. ; exported.
  96.  
  97. MACRO    procstart name            ; Set up model independant proc
  98. if codesize                        ; and export name
  99. PROC    name FAR
  100. else
  101. PROC    name NEAR
  102. endif
  103.         PUBLIC name
  104. ENDM
  105.  
  106. MACRO    procstatic name            ; Set up model independant private proc
  107. if codesize
  108. PROC    name FAR
  109. else
  110. PROC    name NEAR
  111. endif
  112. ENDM
  113.  
  114. MACRO    procnear name            ; Set up near proc
  115. PROC    name NEAR                ; and export name
  116.         PUBLIC name
  117. ENDM
  118.  
  119. MACRO    procfar name            ; Set up far proc
  120. PROC    name FAR                ; and export name
  121.         PUBLIC name
  122. ENDM
  123.  
  124. MACRO    procend name            ; End procedure macro
  125. ENDP    name
  126. ENDM
  127.  
  128. ; Macros for the _BSS data segment. This segment contains uninitialised data.
  129.  
  130. MACRO    begbssseg
  131. SEGMENT    _BSS WORD PUBLIC 'BSS'
  132. ENDM
  133.  
  134. MACRO    endbssseg
  135. ENDS    _BSS
  136. ENDM
  137.  
  138. ; Macros for the _DATA data segment. This segment contains initialised data.
  139.  
  140. MACRO    begdataseg name
  141. ifdef    __HUGE__
  142. SEGMENT &name&_DATA WORD PUBLIC 'DATA'
  143. else
  144. SEGMENT    _DATA WORD PUBLIC 'DATA'
  145. endif
  146. ENDM
  147.  
  148. MACRO    enddataseg name
  149. ifdef    __HUGE__
  150. ENDS    &name&_DATA
  151. else
  152. ENDS    _DATA
  153. endif
  154. ENDM
  155.  
  156. ; Macro to be invoked at the start of all modules to set up segments for
  157. ; later use.
  158.  
  159. MACRO    header name
  160. begdataseg name
  161. enddataseg name
  162. begbssseg
  163. endbssseg
  164. ENDM
  165.  
  166. ; Macro for the main code segment.
  167.  
  168. MACRO    begcodeseg name
  169. if codesize
  170. SEGMENT &name&_TEXT BYTE PUBLIC 'CODE'
  171. ifdef    __HUGE__
  172. GROUP    DGROUP &name&_DATA
  173.         ASSUME CS:&name&_TEXT,DS:DGROUP
  174. else
  175. GROUP    DGROUP _DATA,_BSS
  176.         ASSUME CS:&name&_TEXT,DS:DGROUP
  177. endif
  178. else
  179. SEGMENT _TEXT BYTE PUBLIC 'CODE'
  180. GROUP   DGROUP _DATA,_BSS
  181.         ASSUME CS:_TEXT,DS:DGROUP
  182. endif
  183. ENDM
  184.  
  185. MACRO    endcodeseg name
  186. if codesize
  187. ENDS    &name&_TEXT
  188. else
  189. ENDS    _TEXT
  190. endif
  191. ENDM
  192.  
  193. ; Macros for entering and leaving procedures. Here we automatically save
  194. ; the SI and DI registers that are used as register variables by Borland C++.
  195. ; We also save the DS register in the HUGE model and make it point to our
  196. ; data segment. Upon leaving all registers are restored.
  197.  
  198. MACRO    setupDS
  199.         push    si                        ; Save register variables
  200.         push    di                        ; For Borland C++
  201.  
  202.     IF    hugedata
  203.         push    ds                        ; Save DS
  204.         mov        ax,DGROUP                ; Address our data segment
  205.         mov        ds,ax
  206.     ENDIF
  207. ENDM
  208.  
  209. MACRO    restoreDS
  210.     IF    hugedata
  211.         pop        ds
  212.     ENDIF
  213.         pop        di
  214.         pop        si
  215. ENDM
  216.